package com.amit.jsp;

import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

public class EmailTag extends TagSupport {
	
	private String value;

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public int doEndTag() throws JspException {
		
		Tag tag=getParent();
		if(value.trim().length()!=0)
		{
			if(tag instanceof StudentTag)
			{
				StudentTag stag=(StudentTag)tag;
				Map<String,String> map=stag.getInfo();
				if(map.get("email")==null)
				{
					map.put("email", value);
				}
				else
				{
					String eml=map.get("email");
					map.put("email", eml+"<br/>"+value);
				}
			}
			else
			{
				throw new RuntimeException("Email must be used with Student Tag");
			}
		}
		
		return EVAL_PAGE;
	}
	
	
	

}
